from jsonrpcserver import method, Result, Success, dispatch

#@method
#def tick() -> Result:
#    return Success(f"{datetime.now()}")

from datetime import datetime
class CommonService(object):
    def tick(self) -> Result:
        return Success(f"{datetime.now()}")
    def exit(self) -> Result:
        return Success("exit OK")

services = {
    "tick" : CommonService().tick,
    "exit" : CommonService().exit,
}



from flask import Flask, Response, request
app = Flask(__name__)
@app.route("/api", methods=["POST"])
def index():
    req = request.get_data().decode()
    print(req)
    return Response(dispatch(req, services), \
        content_type="application/json" \
    )


if __name__ == "__main__":
    app.run(debug=True)
